package com.zhong.gang.pda.view;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;

import com.zhong.gang.pda.ui.carorder.OrderNumBean;
import com.zhong.gang.applib.ui.view.ViewClickedListener;
import com.zhong.gang.pda.R;
import com.zhong.gang.pda.databinding.LayoutSendCardBinding;

public class SendCardView extends FrameLayout {
    private LayoutSendCardBinding binding;
    private ViewClickedListener listener;
    private OrderNumBean bean;

    public void setListener(ViewClickedListener listener) {
        this.listener = listener;
    }
    public SendCardView(@NonNull Context context) {
        super(context);
        initView();
    }

    public SendCardView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initView();
    }

    public SendCardView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView();
    }

    private void initView(){
        View view = LayoutInflater.from(getContext()).inflate(R.layout.layout_send_card,null);
        binding = DataBindingUtil.bind(view);
        binding.setView(this);
        if (binding != null) {
            binding.carSnLayout.setVisibility(GONE);
            binding.endAddressLayout.setVisibility(GONE);
            binding.sendAddressLayout.setVisibility(GONE);
            binding.sendCardNumLayout.setVisibility(GONE);
        }
        this.addView(view);
    }

    public void setData(OrderNumBean bean){
        this.bean = bean;
        if (bean == null)
            return;
        binding.sendCarNum.setText(bean.getCarNum());
        binding.carSn.setText(bean.getSn());
        binding.sendAddress.setText(bean.getStartLocal());
        binding.endAddress.setText(bean.getEndLocal());
        binding.sendCardNumLayout.setVisibility(TextUtils.isEmpty(bean.getCarNum())?GONE:VISIBLE);
        binding.carSnLayout.setVisibility(TextUtils.isEmpty(bean.getSn())?GONE:VISIBLE);
        binding.sendAddressLayout.setVisibility(TextUtils.isEmpty(bean.getStartLocal())?GONE:VISIBLE);
        binding.endAddressLayout.setVisibility(TextUtils.isEmpty(bean.getEndLocal())?GONE:VISIBLE);
    }

    public OrderNumBean getBean() {
        return bean;
    }

    public void showEdt(boolean status){
        if (binding != null)
            binding.match.setVisibility(status?VISIBLE:GONE);
    }

    public void setTitle(String str){
        if (TextUtils.isEmpty(str))
            return;
        if (binding == null)
            return;
        binding.title.setText(str);
    }


    public void onViewClicked(View view){
        switch (view.getId()){
            case R.id.match:
                if (listener != null)
                    listener.onViewClicked();
                break;
        }
    }
}
